home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
mpw yacc ƒ src
/
error.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-19
|
4KB
|
217 lines
#include <stdio.h>
#include <signal.h>
#include "defs.h"
#include "files.h"
#include "text.h"
#include "symtab.h"
#ifdef MACINTOSH
#define KILL exit()
#else
#define KILL ((void) kill(getpid(), SIGQUIT))
#endif
extern int lineno;
warn(msg)
char *msg;
{
fprintf(stderr, "warning: %s\n", msg);
}
error(lineno, msg)
int lineno;
char *msg;
{
fprintf(stderr, "File \"%s\"; line %d # error: %s\n",
input_file_name, lineno, msg);
tidy();
exit(1);
}
aborted()
{
fprintf(stderr, "Aborted.\n");
tidy();
exit(2);
}
fatal(msg)
char *msg;
{
fprintf(stderr, "fatal error: %s\n", msg);
tidy();
exit(2);
}
fatal2(msg1, msg2)
char *msg1, *msg2;
{
fprintf(stderr, "fatal error: %s%s\n", msg1, msg2);
tidy();
exit(2);
}
panic(name)
char *name;
{
fprintf(stderr, "PANIC!!! INTERNAL ERROR IN %s\n", name);
KILL;
}
open_error(filename)
char *filename;
{
fatal2("cannot open ", filename);
}
illegal_character(c)
register int c;
{
if (PRINTABLE(c))
fprintf(stderr, "File \"%s\"; line %d # error: illegal character '%c'\n",
input_file_name, lineno, c);
else
fprintf(stderr, "File \"%s\"; line %d # error: illegal character '\\%o'\n",
input_file_name, lineno, c);
tidy();
exit(1);
}
retyped_warning(bp)
bucket *bp;
{
fprintf(stderr, "File \"%s\"; line %d # warning: the type of %s has been \
redeclared\n", input_file_name, lineno, bp->prname);
}
revalued_warning(bp)
bucket *bp;
{
fprintf(stderr, "File \"%s\"; line %d # warning: the token number of %s has been \
redeclared\n", input_file_name, lineno, bp->prname);
}
value_error(value)
int value;
{
fprintf(stderr, "File \"%s\"; line %d # error: the token number %d has been \
assigned to two different tokens", input_file_name, lineno, value);
tidy();
exit(1);
}
reprec_warning(bp)
bucket *bp;
{
fprintf(stderr, "File \"%s\"; line %d # warning: the precedence of %s has been \
redeclared\n", input_file_name, lineno, bp->prname);
}
terminal_start(bp)
bucket *bp;
{
fprintf(stderr, "File \"%s\"; line %d # error: the start symbol %s is a token\n",
input_file_name, lineno, bp->prname);
tidy();
exit(1);
}
no_rhs_warning()
{
fprintf(stderr, "File \"%s\; line %d # warning: the default action assigns an \
undefined value to $$\n", input_file_name, lineno);
}
default_type_clash()
{
fprintf(stderr, "File \"%s\"; line %d # warning: type clash in default action\n",
input_file_name, lineno);
}
int
get_error_line(tp, s)
text *tp;
register char *s;
{
register char *t;
register int n;
n = tp->start_line;
for (t = tp->ch; t < s; t++)
if (*t == NEWLINE) n++;
return (n);
}
type_tag_error(tp, s)
text *tp;
char *s;
{
error(get_error_line(tp, s), "malformed type tag");
}
lhs_type_error(tp, s)
text *tp;
char *s;
{
error(get_error_line(tp, s), "$$ must be typed");
}
dollar_error(tp, s)
text *tp;
char *s;
{
error(get_error_line(tp, s), "malformed $-symbol");
}
rhs_error(tp, s, number, rhslen)
text *tp;
char *s;
int number, rhslen;
{
register int n;
n = get_error_line(tp, s);
fprintf(stderr, "File \"%s\"; line %d # error: $%d appears in an action routine \
for a", input_file_name, n, number);
if (rhslen == 0)
fprintf(stderr, "n empty rule\n");
else if (rhslen == 1)
fprintf(stderr, " rule with only one symbol on its rhs\n");
else
fprintf(stderr, " rule with only %d symbols on its rhs\n", rhslen);
tidy();
exit(1);
}
rhs_type_error(tp, s, number)
text *tp;
char *s;
int number;
{
register int n;
n = get_error_line(tp, s);
fprintf(stderr, "File \"%s\"; line %d # error: $%d must be typed\n",
input_file_name, n, number);
tidy();
exit(1);
}
undefined_warning(bp)
register bucket *bp;
{
fprintf(stderr, "File \"%s\; line %d # warning: %s is undefined\n",
input_file_name, lineno, bp->prname);
}
no_goal(bp)
register bucket *bp;
{
fprintf(stderr, "fatal error: the symbol symbol %s is undefined\n",
bp->prname);
}